<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
 <%@page import=" com.cap.bts.framework.usermgnt.constant.EmployeeStatus"%>   
 <%@page import=" com.cap.bts.framework.usermgnt.constant.ResignCompleted"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>修改人员信息</title>
<%@include file="../../include/include.jsp"%>
	<link rel="stylesheet" type="text/css" href="${csspath}/public.css"/>
	<link rel="stylesheet" type="text/css" href="${csspath}/style_l.css"/>
    <link rel="stylesheet" type="text/css" href="${csspath}/jquery.alerts.css" />
	<link rel="stylesheet" type="text/css" href="${csspath}/datepicker.css"/>
	<script type="text/javascript" src="${jspath}/jquery/jquery-1.4.4.js"></script>
	<script type="text/javascript" src="${jspath}/jquery/jquery.ui.min.js"></script>
	<script type="text/javascript" src="${jspath}/jquery/jquery.blockUI.js"></script>
    <script type="text/javascript" src="${jspath}/jquery/jquery.selectAll.js"></script>
    <script type="text/javascript" src="${jspath}/jquery/jquery.ui.draggable.js"></script>
    <script type="text/javascript" src="${jspath}/ui.datepicker_zh-CN.js"></script>
    <script src="${jspath}/public_ui_embed.js" type="text/javascript" ></script>
    <script type="text/javascript" src="${jspath}/jquery/jquery.alerts.js"></script>
    <script type="text/javascript" src="${jspath}/load_layer.js"></script>
<link rel="stylesheet" type="text/css"
	href="${webcontext}/css/validationEngine.jquery.css" />
<script src="${jspath}/jquery/validate/jquery.validationEngine.js"
	type="text/javascript"></script>
<script src="${jspath}/jquery/validate/jquery.validationEngine-zh.js"
	type="text/javascript"></script>
<link rel="stylesheet" type="text/css"
	href="${webcontext}/css/jquery.alerts.css" />
<style type="text/css">
.formError .formErrorContent {
    -moz-border-radius: 6px 6px 6px 6px;
    -moz-box-shadow: 0 0 6px #000000;
    background: none repeat scroll 0 0 #EE0101;
    border: 2px solid #DDDDDD;
    color: #FFFFFF;
    font-family: tahoma;
    font-size: 11px;
    padding: 4px 10px;
    width: 100px;
}
</style>
<script type="text/javascript">
var workTransferDone = ${submitDto.isDeboardCompleted};
var userGroupCode = "${submitDto.userGroupOrgList[0].userGroupCode}";
$(function(){
	
	addValidationRule();
	
	if( userGroupCode && userGroupCode != "salesmanager"){
		$("#exportData").val(0);
		$("#exportData").attr("disabled","true");
	} 
	
	$("#update_employee").validationEngine(
			{
             promptPosition:"topLeft",
             success:false,
             validationEventTriggers : "change blur",
			 failure:function(){} 
	});
	
	if (${submitDto.employmentStatusId} == <%= EmployeeStatus.NORMAL %> ){
		
		$("#frost").removeAttr("disabled");
	
	}else if (${submitDto.employmentStatusId} == <%= EmployeeStatus.FREEZE %>){
		
    	$("#sqzx").removeAttr("disabled");
		$("#cancelFrost").removeAttr("disabled");
	}
	
	
$("#save").click(function(){
		if(!$("#update_employee").validationEngine(
				{
	             promptPosition:"topLeft",
	             validationEventTriggers : "change blur",
	           	 returnIsValid:true
				 })){
			return;
		}
		$.get("${webcontext}/dm/dealer/employeemgnt/validatecertificatecodeForUpdate?certificatecode=" + $("#certificateCode").val()
				+"&certificateType="+ $("#certificateId").val()
				+"&userCode="+ $("#userCode").val()
				+"&timestamp="+ Date.parse(new Date()), function(result){		
			if (result == "false"){
				jAlert("证件号码已经存在！", "提示信息");
		        $("#certificateCode").val("");
		        return ;
			}else{
				$("#operationType").val("1");
				$("#updateType").val("1");
				jConfirm("确认保存此记录？","确认提示",function(result){
		    		if(result == true)
		    		{	
		            	$("#update_employee").submit();
		    		}
		    	});
			}			
		});
		
		
});

$("#returnBtn").click(function(){
	location.href="${webcontext}/dm/dealer/employeemgnt/returnToEmployeeSearch";
	
});

$("#saveAndSubmit").click(function(){
	if(!$("#update_employee").validationEngine(
			{
             promptPosition:"topLeft",
             validationEventTriggers : "change blur",
           	 returnIsValid:true
			 })){
		return;
	}
	
	$("#operationType").val("2");
	$("#updateType").val("1");
	jConfirm("确认保存此记录？","确认提示",function(result){
		if(result == true)
		{	
        	$("#update_employee").submit();
		}
	});
	
});
	
$("#resetPassword").click(function(){
  
	jConfirm("确认将密码重置？","确认提示",function(result){
		if(result == true)
		{	
			$.get("${webcontext}/dm/dealer/employeemgnt/resetpassword?userCode="+$("#userCode").val(), {},
    			    function(data, textStatus) {
    				if (data == "1")
    			    {
    					jAlert("密码重置成功！","提示信息");
    			    }
    				    
             });	
		}
	});
	
});	
var curUserCode='${userCode}';
$("#frost").click(function(){
	  
	var userCode = $("#userCode").val(); 
	if(userCode==curUserCode){
		jAlert("不能冻结当前登录用户!", "提示信息");
		return ;
	}
	
	jConfirm("确认冻结用户 "+userCode+" ？","确认提示",function(result){
		if(result == true)
		{	
			$.get("${webcontext}/dm/dealer/employeemgnt/frostuser?employeeId="+$("#id").val()+"&timestamp="+Date.parse(new Date()), {},
    			    function(data, textStatus) {
    				if (data == 1 || data == 2)
    			    {
    					jAlert("冻结用户成功！","提示信息");
    					$("#sqzx").removeAttr("disabled");
    					$("#cancelFrost").removeAttr("disabled");
    					$("#frost").attr("disabled", "disabled");
    					workTransferDone = data;
    			    }
    				    
             });	
		}
	});
	
});	

$("#cancelFrost").click(function(){
	  
	var userCode = $("#userCode").val(); 
	jConfirm("确认取消冻结用户 "+userCode+" ？","确认提示",function(result){
		if(result == true)
		{	
			$.get("${webcontext}/dm/dealer/employeemgnt/cancelfrostuser?employeeId="+$("#id").val()+"&timestamp="+Date.parse(new Date()), {},
    			    function(data, textStatus) {
    				if (data == 1 || data == 2)
    			    {
    					jAlert("取消冻结用户成功！","提示信息");
    					$("#frost").removeAttr("disabled");
    					$("#cancelFrost").attr("disabled", "disabled");
    					$("#sqzx").attr("disabled", "disabled");
    					//$("#workStatusId").val(${workStatus });
    					workTransferDone = data;
    			    }
    				    
             });	
		}
	});
	
});	

$("#sqzx").click(function(){
	jConfirm("确认申请注销？","确认提示",function(result){
		if(result == true)
		{	
			var ug = $("#userGroup").text();
			if(ug == '销售顾问' ||ug == '客服专员' ||ug == '电话营销专员'){
				if (workTransferDone != <%= ResignCompleted.COMPLETE.getValue() %>){
					jAlert("移交工作未完成不能申请注销！", "提示信息");
					return;
				}
			}
			loadLayer(this,"${webcontext}/dm/dealer/employeemgnt/applyLogout?employeeId="+$("#id").val(),650,150);
		}
	});
});	

$("#isBrandTraining").change(function(){
	
	var $passTrainingDateStr = $("#passTrainingDateStr");
	
	if(this.value == "1"){
		
		$passTrainingDateStr.parents("td").show();
		$passTrainingDateStr.parents("td").prev().show();
		$passTrainingDateStr.removeAttr("disabled");
		
	}else{
		$passTrainingDateStr.parents("td").hide();
		$passTrainingDateStr.parents("td").prev().hide();
		$passTrainingDateStr.val("");
		$passTrainingDateStr.attr("disabled", "disabled");
		
	}
	
});

$("#hasDriverLicense").change(function(){
	var $obj = $("#driverLicenseDateStr");
	
	if(this.value == "1"){
		
		$obj.parents("td").show();
		$obj.parents("td").prev().show();
		$obj.removeAttr("disabled");
		
	}else{
		$obj.parents("td").hide();
		$obj.parents("td").prev().hide();
		$obj.val("");
		$obj.attr("disabled", "disabled");
	}
	
});

});

function idCardValid(value){
	var strP=/^(\d{15}|(\d{17}[\dXx]))$/;
	if(strP.test(value)){
		return true;
	}else{
		return false;
	}
}

function validateIdCard(){
	   
	   var idCardValue = $("#certificateCode").val();

	   var certificateTypeValue = $("#certificateId").val();
	   
	   if(certificateTypeValue == ${idCardCodeInfo.id}){//选择身份证
		   if(idCardValue && !idCardValid(idCardValue)){
				  return false; 
		   }
	   }
	   
	   return true;
	}
function addValidationRule(){
	   $.validationEngineLanguage.allRules["validateIdCard"] ={ 
	   	        "nname":"validateIdCard", 
	   	        "alertText":"无效的身份证号！"
	   };
}
</script>
 <style type="text/css">
    	.input_tab tr td.yes1{
			display:none;
		}
		.input_tab tr td.yes2{
			display:none;
		}
 </style>
</head>
<!-- content -->
	<div id="content">
		<!-- wrap -->
		<div id="wrap">

			<!-- breadcrumb -->
			<div id="breadcrumb">人员维护</div>
			<!-- /breadcrumb -->

			<!-- info_div -->
			<div class="input_div">
				<div class="title">
					<p>基本资料</p>
				</div>
                <div>
<form:form id="update_employee" action="${webcontext}/dm/dealer/employeemgnt/updateEmployee" method="post" modelAttribute="submitDto" enctype="multipart/form-data">
 <form:hidden path="id"/>
 <input type="hidden" id="updateType" name="updateType"/>
 <input type="hidden" id="operationType" name="operationType"/>
                  <table class="input_tab">
                    <tr>
                      <td align="center" valign="middle" rowspan="12"><img width="60px" height="70px"  src="${submitDto.photoUrl }" alt=""/></td>
                      <td class="label" >上传照片：</td>
                      <td colspan="5"><input type="file" name="photoFile" style="" /></td>
                      
                    </tr>
                    <tr>
  <td colspan="6" class="spliterInput_Line">
    <img src="${webcontext}/images/pictures_l/spliterInput_line_03.gif" width="550" height="9" />
  </td>
</tr>
                    <tr>
                      <td class="label">用户ID：</td>
                      <td><form:input path="userCode" cssClass="text string" readonly="true"/></td>
                      <td class="label">销售顾问<br />
                                                           等级：</td>
                      <td><input type="text" class="text" value="${saleConsultLevel}" readonly="true" /></td>
                      <td class="label">&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td class="label">员工姓名：</td>
                      <td><form:input path="employeeName" cssClass="text string" readonly="true"/></td>
                      <td class="label"><span class="need">*</span>性别：</td>
                      <td> <form:select path="genderId" cssClass="validate[required] sel">  
					  	 <form:option value="">请选择</form:option>
					  	   <core:forEach items="${gender}" var="codeInfo">
				         <form:option value="${codeInfo.id }">${codeInfo.value }</form:option>
				        </core:forEach>	
						</form:select></td>
                      <td class="label"><p><span class="need">*</span>手机：</p></td>
                      <td><form:input path="mobilePhone" cssClass="validate[custom[mobilePhone]] text"/></td>
                    </tr>
                    <tr>
                      <td class="label"><p><span class="need">*</span>可导出数据：</p></td>
                      <td><form:select path="exportData" cssClass="validate[required] sel">  
					  	 <form:option value="">请选择</form:option>
					  	 <%= CodeTextUtils.getOptions("EmployeeInfo.ExportData","" ) %>
						</form:select>
						 <script type="text/javascript">
						$("#exportData").val("${submitDto.exportData}");
						</script>
						</td>
                      <td class="label"><span class="need">*</span>电子邮件：</td>
                      <td colspan="3"><form:input path="email" cssClass="validate[custom[email],charLength[0,100]] text" cssStyle="width:386px;"/></td>
                    </tr>
                    <tr>
                      <td class="label"><span class="need">*</span>证件类型：</td>
                      <td><form:select path="certificateId" cssClass="validate[required] sel">  
					  	   <form:option value="">请选择</form:option>
					  	   <core:forEach items="${certificateType}" var="codeInfo">
				         <form:option value="${codeInfo.id }">${codeInfo.value }</form:option>
				        </core:forEach>	
						</form:select></td>
                      <td class="label"><span class="need">*</span>证件号码：</td>
                      <td><form:input path="certificateCode" cssClass="validate[required,length[0,40]],funcCall[validateIdCard] text"/></td>
                      <td class="label"><span class="need">*</span>婚姻状况：</td>
                      <td><form:select path="marriageId" cssClass="validate[required] sel">  
					  	 <form:option value="">请选择</form:option>
					  	   <core:forEach items="${marriage}" var="codeInfo">
				         <form:option value="${codeInfo.id }">${codeInfo.value }</form:option>
				        </core:forEach>	
						</form:select></td>
                    </tr>
                    <tr>
                      <td class="label"><span class="need">*</span>籍贯：</td>
                      <td><form:input path="birthPlace" cssClass="validate[required,length[0,500]] text"/></td>
                      <td class="label"><span class="need">*</span>生日：</td>
                      <td><form:input path="birthDateStr" cssClass="validate[custom[date]] text date"/></td>
                      <td class="label"><span class="need">*</span>学历：</td>
                      <td> <form:select path="educationId" cssClass="validate[required] sel">  
					  	   	 <form:option value="">请选择</form:option>
					  	   <core:forEach items="${education}" var="codeInfo">
				         <form:option value="${codeInfo.id }">${codeInfo.value }</form:option>
				        </core:forEach>	
						</form:select></td>
                    </tr>
                    <tr>
                      <td class="label"><span class="need">*</span>住址：</td>
                      <td colspan="3"><form:input path="address" cssClass="validate[required,length[0,255]] text" cssStyle="width:386px;"/></td>
                      <td class="label">就业状态：</td>
                      <td><input path="workStatusId" type="text" name="" value="${workStatus }" id="workStatus" class="text" readonly="true" /></td>
                    </tr>
                    <tr>
  <td colspan="6" class="spliterInput_Line">
    <img src="${webcontext}/images/pictures_l/spliterInput_line_03.gif" width="550" height="9" />
  </td>
</tr>
                    <tr>
                      <td class="label"><p><span class="need">*</span>目前岗位入职</p>
                        <p>日期：</p></td>
                      <td><form:input path="onboardDateStr" cssClass="validate[custom[date]] text date"/></td>
                      <td class="label"><p><span class="need">*</span>首服务品牌</p>
                        <p>日期：</p></td>
                      <td><form:input path="brandFirstServiceDateStr" cssClass="validate[custom[date]] text date"/></td>
                      <td class="label">&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td class="label"><p><span class="need">*</span>是否受过品牌培训：</p></td>
                      <td><form:select path="isBrandTraining" cssClass="validate[required] sel">  
					  	 <form:option value="">请选择</form:option>
					  	 <%= CodeTextUtils.getOptions("EmployeeInfo.yesOrNo","" ) %>
						</form:select>
						 <script type="text/javascript">
						$("#isBrandTraining").val("${submitDto.isBrandTraining}");
						</script>
						</td>
                      <td class="label yes1" style="display:none;"><p><span class="need">*</span>通过岗位培训日期：</p></td>
                      <td class="yes1" style="display:none;"><form:input path="passTrainingDateStr" cssClass="validate[custom[date]] text date" disabled="true"/></td>
                      <td class="label">&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                    <tr>
                      <td class="label"><p><span class="need">*</span>是否有驾照：</p></td>
                      <td><form:select path="hasDriverLicense" cssClass="validate[required] sel">  
					  	 <form:option value="">请选择</form:option>
					  	  <%= CodeTextUtils.getOptions("EmployeeInfo.yesOrNo","" ) %>
						</form:select>
						 <script type="text/javascript">
						$("#hasDriverLicense").val("${submitDto.hasDriverLicense}");
						</script>
						</td>
                      <td class="label yes2" style="display:none;"><p><span class="need">*</span>领照日期：</p></td>
                      <td class="yes2" style="display:none;"><form:input path="driverLicenseDateStr" cssClass="validate[custom[date]] text date" disabled="true"/></td>
                      <td>&nbsp;</td>
                      <td>&nbsp;</td>
                    </tr>
                  </table>
                </div>
			</div>
			<!-- /info_div -->
            
            <div class="spliter h_5"></div>
            
            <!-- info_div -->
			<div class="info_div">
            	<div class="title"><p title="点击展开/隐藏详细信息">岗位与组织</p>
           	  </div>
                <div>
                  <div class="data_div">
                  <table class="data_tab">
                            <tr>
                              <th class="w_20">岗位</th>
                              <th class="w_20">默认岗位</th>
                                <th class="w_20">组织名称</th>
                                <th class="w_20">组织主管</th>
                                <th class="w_20">上级组织名称</th>
                            </tr>
                            <core:forEach items="${submitDto.userGroupOrgList}" var="userGroupOrg">
                            <tr>
                              <td>${userGroupOrg.userGroupName}</td>
                        	  <td id="userGroup">${userGroupOrg.defUserGroupName}</td>
                              <td class='align_right'>${userGroupOrg.orgName} </td>
                              <td class='align_right'>${userGroupOrg.orgManager}</td>
                              <td class='align_right'>${userGroupOrg.advancedOrgName}</td>
                            </tr>
                            </core:forEach>
                        </table>
                    </div>
                </div>
			</div>
			<!-- /info_div -->
            
            <div class="spliter h_5"></div>
    
            <div class="btn_div">
                <input type="button" class="btn" value="保存"  id="save"/>
                <!-- <input type="button" class="btn" value="保存并提交"  id="saveAndSubmit"/> -->
                <input type="button" class="btn" value="密码重置" id="resetPassword"/> 
                <input type="button" class="btn" value="冻结" id="frost" disabled="disabled"/> 
                <input type="button" class="btn" value="取消冻结" id="cancelFrost" disabled="disabled"/> 
                <input type="button" class="btn" value="申请注销" id="sqzx" disabled="disabled"/>
                <input type="button" class="btn" value="返回" id="returnBtn"/>
            </div>
</form:form>            
		</div>
		<!-- /wrap -->
	</div>
	<!-- /content -->
  </body>
</html>